package com.ljw.spring.annotation.test;

import com.ljw.spring.annotation.bean.Dog;
import com.ljw.spring.annotation.conf.ConfigOfPropertyValue;
import com.ljw.spring.annotation.conf.MyConfig;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;

/**
 * @FileName IOCTest_PropertyValue
 * @Description TODO
 * @Author ljw
 * @Date 2021/2/2 22:35
 * @Version 1.0
 */
public class IOCTest_PropertyValue {

    @Test
    public void test01(){
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConfigOfPropertyValue.class);
        //获取在IOC容器中注册的所有实例对象
        String[] beanNames = context.getBeanDefinitionNames();
        for (String beanName : beanNames) {
            System.out.println("ioc容器中的bean："+beanName);
        }

        Dog dog = context.getBean(Dog.class);
        System.out.println(dog);

        //使用environment.getProperty（key）取配置文件中的值
        ConfigurableEnvironment environment = context.getEnvironment();
        String property = environment.getProperty("dog.hight");
        System.out.println(property);
    }
}
